﻿using System;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using ExoticCarRental;

namespace ExoticCardRentalTest
{
    public partial class TestApp : Form
    {
        BusinessLayer bl = new BusinessLayer();

        public TestApp()
        {
            InitializeComponent();

            DataTable dt = new DataTable();
            dt = bl.GetLocations();
            cboLocation.DataSource = dt;
            cboLocation.DisplayMember="addr";
            cboLocation.ValueMember = "location_id";

            cboResLocation.DataSource = dt;
            cboResLocation.DisplayMember = "addr";
            cboResLocation.ValueMember = "location_id";

            dt = new DataTable();
            dt = bl.GetCategories();

            cboResCategory.DataSource = dt;
            cboResCategory.DisplayMember = "category_name";
            cboResCategory.ValueMember = "category_id";


            cboRentalCategory.DataSource = dt;
            cboRentalCategory.DisplayMember = "category_name";
            cboRentalCategory.ValueMember = "category_id";

          



            dt = new DataTable();
            dt = bl.GetCountries();
            cboCountry.DataSource = dt;
            cboCountry.DisplayMember = "Country";
            cboCountry.ValueMember = "Country";

            dt = new DataTable();
            dt = bl.GetReservationLookUp();
            cboRentResevations.DataSource = dt;
            cboRentResevations.DisplayMember = "ReservationKey";
            cboRentResevations.ValueMember = "reservation_id";

            dt = new DataTable();
            dt = bl.GetCountries();
            cboRentCountry.DataSource = dt;
            cboRentCountry.DisplayMember = "Country";
            cboRentCountry.ValueMember = "Country";


            dt = new DataTable();
            dt = bl.GetCustomerLookUp();
            cboCustCustID.DataSource = dt;
            cboCustCustID.DisplayMember = "CustomerKey";
            cboCustCustID.ValueMember = "cust_id";



            

        }

        private void btnCreateLogin_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            int ret = bl.CreateLogin(txtEmail.Text, txtPassword.Text);
            if (ret == 0)
            {
                MessageBox.Show("Customer created successfully!");
            }
            else
            {
                MessageBox.Show("Customer already exists!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            if (bl.LoginCustomer(login.Text, password.Text) == 0)
            {
                MessageBox.Show("pass");
            }
            else
            {
                MessageBox.Show("fail");
            }


        }

        private void label15_Click(object sender, EventArgs e)
        {

        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {

        }

        private void cboCategory_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox10_TextChanged(object sender, EventArgs e)
        {

        }

        private void label18_Click(object sender, EventArgs e)
        {

        }

        private void textBox9_TextChanged(object sender, EventArgs e)
        {

        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void label16_Click(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void label19_Click(object sender, EventArgs e)
        {

        }

        private void tbReservations_Click(object sender, EventArgs e)
        {

        }

        private void btnCreateReservation_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            int reservation_id = bl.CreateReservation(txtResEmail.Text, txtResLastName.Text, txtResFirstName.Text,Convert.ToDateTime(txtResPickUpDate.Text), Convert.ToDateTime(txtResDropOffDate.Text), Convert.ToInt32(cboResLocation.SelectedValue), Convert.ToInt32(cboResCategory.SelectedValue), txtResCardNo.Text, cboResCardType.Text, Int32.Parse(txtResCardExpMonth.Text), Int32.Parse(txtResCardExpYear.Text));
            MessageBox.Show(reservation_id.ToString());
        }

        private void tbRental_Click(object sender, EventArgs e)
        {

        }

        private void tbCustomer_Click(object sender, EventArgs e)
        {

        }

        private void btnCreateCustomer_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            DataRow row = bl.CreateCustomer(txtCustCreateEmail.Text, 
                                            txtCustCreateLastName.Text, 
                                            txtCustCreateFirstName.Text,
                                            txtCustCreateAddr1.Text, 
                                            txtCustCreateAddr2.Text, 
                                            txtCustCreateCity.Text, 
                                            txtCustCreateState.Text, 
                                            cboCountry.SelectedValue.ToString(), 
                                            txtCustCreatePostalCode.Text, 
                                            txtCustCreateLIC.Text, 
                                            Convert.ToDateTime(txtCustCreateDOB.Text), 
                                            txtCustCreatePhone.Text);

            MessageBox.Show(row["cust_id"].ToString());

        }

        private void button3_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            //DataRow row = bl.CreateRental();

        }

        private void cboRentResevations_SelectionChangeCommitted(object sender, EventArgs e)
        {
            //get reservation by reservation_id
            DataRow row = bl.GetReservationByReservationID(Convert.ToInt32(cboRentResevations.SelectedValue.ToString()));
            txtRentEmail.Text = row["email_addr"].ToString();

        }

        private void label26_Click(object sender, EventArgs e)
        {

        }

        private void txtRentState_TextChanged(object sender, EventArgs e)
        {

        }

        private void TestApp_Load(object sender, EventArgs e)
        {

        }

        private void btnCreateCard_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            int ret = bl.CreateCustomerCreditCard(Convert.ToInt32(cboCustCustID.SelectedValue.ToString()), txtCustCardNo.Text, txtCustCardType.Text, Convert.ToInt32(cboExpiryMonth.Text), Convert.ToInt32(cboExipiryYear.Text));
            MessageBox.Show(ret.ToString());

        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox13_TextChanged(object sender, EventArgs e)
        {

        }

        

 

    

  


        



    

      
    }
}
